// 引入axios组件
import axios from 'axios';
import qs from 'qs'; // 处理数据  qs.stringify(params)
import { checkRule } from '@/assets/js/public';
// 引入公共js文件
export default {
  // props: ["info"],

  data() {
    return {
      modal1: false, // 模态弹框代码
      baktitle: '', // 弹框内的标题
      param: '', // 删除和恢复的id（数据）
      bakdata: '', // 删除和备份需要的参数
      // dbList:"",
      columns7: [
        {
          type: 'selection',
          width: 60,
          align: 'center',
        },
        {
          title: '文件名',
          key: 'filename',
          render: (h, params) =>
            h('div', [
              h('Icon', {
                props: {
                  type: 'person',
                },
              }),
              h('strong', params.row.filename),
            ]),
        },
        // {
        //   title: "文件大小",
        //   key: "size"
        // },
        {
          title: '备份时间',
          key: 'backtime',
        },
        {
          title: '操作选项',
          key: 'action',
          width: 150,
          align: 'center',
          render: (h, params) =>
            h('div', [
              h(
                'Button',
                {
                  props: {
                    type: 'info',
                    size: 'small',
                  },
                  style: {
                    marginRight: '5px',
                  },
                  on: {
                    click: () => {
                      this.show(params.row.id);
                    },
                  },
                },
                '还原',
              ),
              h(
                'Button',
                {
                  props: {
                    type: 'error',
                    size: 'small',
                  },
                  style: {
                    marginRight: '5px',
                  },
                  on: {
                    click: () => {
                      // this.remove(params.index);
                      this.remove(params.row.id);
                    },
                  },
                },
                '删除',
              ),
            ]),
        },
      ],
    };
  },
  created() {
    this.$Spin.show();
    setTimeout(() => {
      this.$Spin.hide();
    }, 500);
  },
  // 用来获取VUEX中的文件
  computed: {
    data6() {
      return this.$store.state.bak.baklist;
    },
  },
  // 传说中的方法
  methods: {
    // 控制全选，全不选
    handleSelectAll(status) {
      this.$refs.selection.selectAll(status);
    },
    // 控制弹窗是否展示
    show(index) {
      this.bakdata = { tp: 'restore', name: index };
      this.modal1 = true;
      this.param = index;
      this.baktitle = '确定要还原数据？';
    },
    // 删除方法
    remove(index) {
      this.bakdata = { tp: 'del', name: index };
      this.modal1 = true;
      this.param = index;
      this.baktitle = '确定要删除当前备份？';
    },
    // 添加数据备份方法
    backup() {
      const bakdata = { tp: 'backup', name: '' };
      console.log(bakdata);
      // this.$store.commit("callaxios", bakdata,this);
      this.callaxios(bakdata);
    },
    // 删除，还原点击确定之后走的方法
    ok() {
      const self = this;
      axios({
        method: 'post',
        url: '/admin/dbbak/bak',
        data: this.bakdata,
      })
        .then((response) => {
          checkRule(response, self); // 检查是否有权限
          // self.$store.commit("saveDbListInfo", response.data.dblist);
          if (response.data.code == 1) {
            self.$store.commit('saveDbListInfoAgain');
            self.$Message.success('操作成功');
          } else if (
            response.data.code == -1 &&
            response.data.code != undefined
          ) {
            self.$Message.error('操作失败');
          }
        })
        .catch((response) => {});
    },
    //  删除，还原点击取消之后走的方法
    cancel() {
      this.modal1 = false;
    },
    // 备份需要的方法
    callaxios(bakdata) {
      const self = this;
      axios({
        method: 'post',
        url: '/admin/dbbak/bak',
        data: bakdata,
      })
        .then((response) => {
          checkRule(response, self); // 检查是否有权限
          // self.$store.commit("saveDbListInfo", response.data.dblist);
          if (response.data.code == 1) {
            self.$store.commit('saveDbListInfoAgain');
            self.$Message.success('操作成功');
          } else if (
            response.data.code == -1 &&
            response.data.code != undefined
          ) {
            self.$Message.error('操作失败');
          }
        })
        .catch((response) => {});
    },
  },
};
